<?php
/**
 * Description of Session
 *
 * @author dan
 */
class Session {
    
    private static $sessionStarted = false;

    /**
     *
     * @var Session 
     */
    private static $instance = null;

    private function __construct() {
        
        if(session_id()){
            self::$sessionStarted = true;
        } else {
            self::$sessionStarted = false;
        }
        
        if(!self::$sessionStarted){
            session_start();
            self::$sessionStarted = true;
        }
    }

    /**
     *
     * @return Session 
     */
    public static function getInstance(){
        if(self::$instance == null){
            self::$instance = new Session();
        }
        return self::$instance;
    }

    public function get($key){
        if(isset($_SESSION[$key])){
            return $_SESSION[$key];
        }
        return false;
    }
    
    public function set($key, $value){
        $_SESSION[$key] = $value;
    }
    
    public function endSession(){
        if(self::$sessionStarted){
            session_destroy();
            unset($_SESSION);
            self::$sessionStarted = false;
        }
    }
    
    
}